<?php
/**

*/
class App_DBConn {
	/**
	 * static property to hold singleton instance
	 */
	static $instance = NULL;
	/**
	 * constructor
	 * private so only getInstance() method can instantiate
	 * @return void
	 */
	private function __construct()
	{
		
	}

	private function __clone()
	{

	}
	/**
	 * factory method to return the singleton instance
	 * @return DbConn
	 */
	public static function getInstance($dbInfo)
	{
		///error_log(print_r($dbInfo, true));
		
		if (self::$instance == NULL)
		{
	    try 
	    {    
	      self::$instance = Zend_Db::factory('Pdo_Mysql', $dbInfo);    
	      self::$instance->setFetchMode ( Zend_Db::FETCH_ASSOC );
	      self::$instance->query ( "set names 'utf8'" ); 
	      self::$instance->getProfiler()->setEnabled(true);     
	    } catch (Zend_Db_Adapter_Exception $e) {       
	      // perhaps a failed login credential, or perhaps the RDBMS is not running
	      App_Log::info($e->getMessage());
	      throw new Zend_Exception('DB error');
	       
	    } catch (Zend_Exception $e) {      
	      // perhaps factory() failed to load the specified Adapter class
	      App_Log::info($e->getMessage());
	      throw new Zend_Exception('Connection error'); 
	    }
		}

		return self::$instance;
	}
}
?>